package com.supreme.studyserver.service;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class PressureService {

    private Thread simpleThread;

    public void simpleTest(int count) {
        simpleThread = new Thread(() -> {
            try {
                List<byte[]> bufferList = new ArrayList<>();
                for (int i = 0; i < count; i++) {
                    TimeUnit.MILLISECONDS.sleep(2000);
                    byte[] buffer = new byte[1024 * 1024];
                    bufferList.add(buffer);
                    System.out.println("run: " + i + " interrupt: " + Thread.currentThread().isInterrupted());
                }
            } catch (InterruptedException e) {
                System.out.println(e.getMessage() + " " + Thread.currentThread().isInterrupted());
            }
        });
        simpleThread.start();
    }

    public void interruptThread() {
        if (simpleThread != null) {
            simpleThread.interrupt();
        }
    }
}
